package com.zx.eval.api.admin;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.zx.common.utils.ShiroUtils;
import com.zx.sys.user.api.AbstractApi;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zx.eval.entity.EvalQuestionEntity;
import com.zx.eval.service.EvalQuestionService;
import com.zx.common.utils.PageUtils;
import com.zx.common.utils.R;



/**
 * 测评问题表
 *
 * @author LiYe@zx
 * @email ily_hxy@163.com
 * @date 2020-03-29 18:15:40
 */
@RestController
@RequestMapping("eval/evalquestion")
public class EvalQuestionApi extends AbstractApi {
    @Autowired
    private EvalQuestionService evalQuestionService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("eval:evalquestion:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = evalQuestionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("eval:evalquestion:info")
    public R info(@PathVariable("id") Integer id){
		EvalQuestionEntity evalQuestion = evalQuestionService.getById(id);

        return R.ok().put("info", evalQuestion);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("eval:evalquestion:save")
    public R save(@RequestBody EvalQuestionEntity evalQuestion){
        Long userId = ShiroUtils.getUserId();
        evalQuestion.setCreateTime(new Date());
        evalQuestion.setCreator(userId);
		evalQuestionService.save(evalQuestion);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("eval:evalquestion:update")
    public R update(@RequestBody EvalQuestionEntity evalQuestion){
        Long userId = ShiroUtils.getUserId();
        evalQuestion.setUpdateTime(new Date());
        evalQuestion.setUpdater(userId);
		evalQuestionService.updateById(evalQuestion);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("eval:evalquestion:delete")
    public R delete(@RequestBody Integer[] ids){
		evalQuestionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
